package com.yellowpage.ndc.service;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.yellowpage.white.common.Constants;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;

import com.yellowpage.ndc.data.Address;
import com.yellowpage.ndc.dao.AddressDao;

public class AddressServiceImpl extends BaseServiceImpl implements AddressService {
	  private AddressDao addressDao;
	
	  public void setAddressDao(AddressDao addressDao) {
		  this.addressDao = addressDao;
	  }
	
	
	  /* Smooth generate Method */ 
	  public Address getAddress(Long id){
	      return addressDao.get(id);
	  }
	  
    public List<Address> getAllAddress(){
        return addressDao.getAll();
    }
    
    public List<Map> queryAddressByPage(Map queryMap, PageRender pageRender) {		
        
		QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
				"SELECT a.ADDR_ID , a.REGION_CODE , a.ADDR , a.ADDR_BRIEF , a.ADDR_NUM , a.ADDR_LAST , a.ZIP , a.PY_ADDR , a.ENG_ADDR , " +
				"      a.MODIFY_TIME , a.MODIFY_EMP_ID , a.POIX , a.POIY    " +
				" FROM db_ndc.ADDRESS a WHERE 1=1 ")
				    			.addCondition(" and ADDR_ID = :addrId ")
							    			.addCondition(" and REGION_CODE = :regionCode ")
							    			.addCondition(" and ADDR = :addr ")
							    			.addCondition(" and ADDR_BRIEF = :addrBrief ")
							    			.addCondition(" and ADDR_NUM = :addrNum ")
							    			.addCondition(" and ADDR_LAST = :addrLast ")
							    			.addCondition(" and ZIP = :zip ")
							    			.addCondition(" and PY_ADDR = :pyAddr ")
							    			.addCondition(" and ENG_ADDR = :engAddr ")
							    		    .addCondition(" and date_format(MODIFY_TIME,'%Y-%m-%d') =  :modifyTime  ")
		    				    			.addCondition(" and MODIFY_EMP_ID = :modifyEmpId ")
							    			.addCondition(" and POIX = :poix ")
							    			.addCondition(" and POIY = :poiy "); 		    
		    

		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;
	}
    
    
    public void saveAddress(Address address){
        addressDao.save(address);
    }
    
	  public void updateAddress(Address address){
	      addressDao.update(address);
	  }
	  
	  public void delete(List deleteList){
	      addressDao.remove(deleteList);
	  }
	  
	  
	 
	
}	